# Makefile for drbd.o
#
# This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
#
# drbd is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# drbd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with drbd; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#

VPATH = ../shared

# variables set by configure
DISTRO = @DISTRO@
prefix = @prefix@
exec_prefix = @exec_prefix@
localstatedir = @localstatedir@
datarootdir = @datarootdir@
datadir = @datadir@
sbindir = @sbindir@
sysconfdir = @sysconfdir@
BASH_COMPLETION_SUFFIX = @BASH_COMPLETION_SUFFIX@
UDEV_RULE_SUFFIX = @UDEV_RULE_SUFFIX@
INITDIR = @INITDIR@
LIBDIR = @prefix@/lib/@PACKAGE_TARNAME@
CC = @CC@
CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
LN_S = @LN_S@

# features enabled or disabled by configure
WITH_84_SUPPORT = @WITH_84_SUPPORT@
WITH_UDEV = @WITH_UDEV@
WITH_XEN = @WITH_XEN@
WITH_PACEMAKER = @WITH_PACEMAKER@
WITH_RGMANAGER = @WITH_RGMANAGER@
WITH_BASHCOMPLETION = @WITH_BASHCOMPLETION@
WITH_CLITEST = @WITH_CLITEST@

# variables meant to be overridden from the make command line
DESTDIR ?= /

CFLAGS += -Wall -I. -I../shared
CFLAGS += $(EXTRA_CFLAGS)

drbdadm-obj = drbdadm_scanner.o drbdadm_parser.o drbdadm_main.o \
	      drbdadm_adjust.o drbdtool_common.o drbdadm_usage_cnt.o \
	      drbd_buildtag.o registry.o config_flags.o libgenl.o \
	      drbd_nla.o shared_tool.o shared_main.o shared_parser.o \
	      libnla.o path_linux.o shared_linux.o

drbdsetup-obj = libgenl.o registry.o drbdsetup.o drbdtool_common.o \
		drbd_buildtag.o drbd_strings.o config_flags.o drbd_nla.o \
		wrap_printf.o drbdsetup_colors.o shared_tool.o libnla.o \
		path_linux.o shared_linux.o

all-obj := $(drbdadm-obj) $(drbdsetup-obj)

all: tools

../shared_prereqs.mk: ;
include ../shared_prereqs.mk

ifeq ($(WITH_84_SUPPORT),yes)
tools: drbdadm-84 drbdsetup-84
else
tools:
endif

.PHONY: drbdadm drbdsetup
drbdadm drbdsetup:
	echo >&2 "You meant to ask for $@-84" ; exit 1

drbdadm-84: $(drbdadm-obj)
	$(LINK.c) $(LDFLAGS) -o $@ $^

drbdadm_scanner.c: drbdadm_scanner.fl drbdadm_parser.h
	flex -s -odrbdadm_scanner.c drbdadm_scanner.fl

drbdsetup-84: $(drbdsetup-obj)
	$(LINK.c) $(LDFLAGS) -o $@ $^

ifeq ($(WITH_84_SUPPORT)$(WITH_CLITEST),yesyes)
test: drbdadm-84
	cd ../../tests/v84 && ln -sf ../../user/v84/drbdadm-84 ./drbdadm
	../../tests/run.sh ../../tests/v84/*.test
else
test:
endif

clean:
	rm -f drbdadm_scanner.c
	rm -f drbdsetup-84 drbdadm-84 $(all-obj)
	rm -f *~

distclean: clean
	rm -f $(all-dep)

install:
ifeq ($(WITH_84_SUPPORT),yes)
	install -d $(DESTDIR)$(localstatedir)/lib/drbd
	install -d $(DESTDIR)$(localstatedir)/run/drbd
	install -d $(DESTDIR)$(localstatedir)/lock
	install -d $(DESTDIR)/lib/drbd/
	if getent group haclient > /dev/null 2> /dev/null ; then	\
		install -g haclient -m 4750 drbdsetup-84 $(DESTDIR)/lib/drbd/ ;	\
		install -m 755 drbdadm-84 $(DESTDIR)/lib/drbd/ ;		\
	else								\
		install -m 755 drbdsetup-84 $(DESTDIR)/lib/drbd/ ;		\
		install -m 755 drbdadm-84 $(DESTDIR)/lib/drbd/ ; 		\
	fi
endif

uninstall:
	rm -f $(DESTDIR)/lib/drbd/drbdsetup-84
	rm -f $(DESTDIR)/lib/drbd/drbdadm-84

spell:
	for f in drbdadm_adjust.c drbdadm_main.c drbdadm_parser.c drbdadm_usage_cnt.c drbdsetup.c drbdtool_common.c; do \
	 	aspell --save-repl --dont-backup --personal=./../documentation/aspell.en.per check $$f; \
	done

.PHONY: install uninstall clean distclean
../../configure:
	@echo "please (re-)run ./autogen.sh with appropriate arguments"; exit 1
../../config.status: ../../configure
	@echo "please (re-)run ./configure with appropriate arguments"; exit 1
Makefile.in: ;
Makefile: Makefile.in ../../config.status
	cd ../.. && ./config.status user/v84/Makefile

